home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / PlayerPRO 4.5.5 Dev.Kit / Plug-Ins / Sound Filters Plugs / Amplitude.c < prev    next >
C/C++ Source or Header  |  1995-10-08  |  4KB  |  154 lines

  1. /*
  2.     Player PRO 4.4x PlugIns
  3.  
  4.     Antoine ROSSET
  5.     16 Tranchees
  6.     1206 GENEVA
  7.     SWITZERLAND
  8.     
  9.     FAX: 022 789 35 03
  10.     Compuserve: 100277,164
  11. */
  12.  
  13. #include "MAD.h"
  14. #include "PPPlug.h"
  15.  
  16. #if defined(powerc) || defined(__powerc)
  17. enum {
  18.         PlayerPROPlug = kCStackBased
  19.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  20.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( sData*)))
  21.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( long)))
  22.         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( long)))
  23.         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoPlug*)))
  24. };
  25.  
  26. ProcInfoType __procinfo = PlayerPROPlug;
  27. #else
  28. #include <A4Stuff.h>
  29. #endif
  30.  
  31.  
  32. GDHandle    TheGDevice:0xCC8;
  33.  
  34. void AutoPosition( DialogPtr aDia)
  35. {
  36.     Point    Position, mouse;
  37.     Rect    ViewRect;
  38.     short    XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
  39.  
  40.  
  41.     GetMouse( &mouse);
  42.     LocalToGlobal( &mouse);
  43.  
  44.     SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
  45.                         (*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
  46.  
  47.     Position.h = mouse.h - XSize/2;
  48.     if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
  49.     else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
  50.  
  51.     Position.v = mouse.v - YSize/2;
  52.     if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
  53.     else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
  54.  
  55.     MoveWindow( aDia, Position.h, Position.v, false);
  56.  
  57.     ShowWindow( aDia);
  58. }
  59.  
  60.  
  61. Boolean getParams ( long *p1, PPInfoPlug *thePPInfoPlug)
  62. {
  63. DialogPtr    theDialog;
  64. Boolean        theResult = false;
  65.  
  66.     theDialog = GetNewDialog( 128,nil,(WindowPtr)-1);
  67.     if (theDialog) {
  68.         short    iType, itemHit;
  69.         Handle    iHandle;
  70.         Rect    iRect;
  71.         Str255    textStr;
  72.         
  73.         SetPort( theDialog);
  74.         AutoPosition( theDialog);
  75.         GetDItem(theDialog,3,&iType,&iHandle,&iRect);
  76.         NumToString( *p1, textStr);
  77.         SetIText( iHandle, textStr);
  78.         SelIText( theDialog, 3, 0, 32767);
  79.  
  80.         do
  81.         {
  82.             #if defined(powerc) || defined(__powerc)
  83.             ModalDialog( thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  84.             #else
  85.             ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
  86.             #endif
  87.         }
  88.         while ((itemHit != ok) && (itemHit != cancel));
  89.         
  90.         if (itemHit == ok)
  91.         {
  92.             theResult = true;
  93.             GetDItem( theDialog, 3,&iType,&iHandle,&iRect);
  94.             GetIText( iHandle, textStr);
  95.             StringToNum( textStr, p1);
  96.         }
  97.         DisposDialog(theDialog);
  98.     }
  99.     return theResult;
  100. }
  101.  
  102. OSErr main(     sData                    *theData,
  103.                 long                    SelectionStart,
  104.                 long                    SelectionEnd,
  105.                 PPInfoPlug                *thePPInfoPlug)
  106. {
  107. long            i, temp, Inc;
  108. Ptr                Sample8Ptr = theData->data;
  109. short            *Sample16Ptr = (short*) theData->data;
  110.  
  111.     Inc = 120;
  112.     if( getParams( &Inc, thePPInfoPlug))
  113.     {
  114.         switch( theData->amp)
  115.         {
  116.             case 8:
  117.                 Sample8Ptr += SelectionStart;
  118.                 
  119.                 for( i = 0; i < SelectionEnd - SelectionStart; i++)
  120.                 {
  121.                     temp = *Sample8Ptr;
  122.                     if( temp >= 0x80) temp -= 0xFF;
  123.                         
  124.                     temp *= Inc;
  125.                     temp /= 100L;
  126.                     if( temp >= 127) temp = 127;
  127.                     else if( temp <= -127 ) temp = -127;
  128.                         
  129.                     *Sample8Ptr = temp;
  130.                     Sample8Ptr++;
  131.                 }
  132.             break;
  133.             
  134.             case 16:
  135.                 Sample16Ptr += SelectionStart/2;                        // Div 2, because it's in bytes !!!
  136.             
  137.                 for( i = 0; i < (SelectionEnd - SelectionStart)/2; i++)    // Div 2, because it's in bytes !!!
  138.                 {
  139.                     temp = *Sample16Ptr;
  140.                     
  141.                     temp *= Inc;
  142.                     temp /= 100L;
  143.                     
  144.                     if( temp >= (short) 0x7FFF) temp = 0x7FFF;    // overflow ?
  145.                     else if( temp <= (short) 0x8000 ) temp = (short) 0x8000;
  146.  
  147.                     *Sample16Ptr = temp;
  148.                     Sample16Ptr++;
  149.                 }
  150.             break;
  151.         }
  152.     }
  153.     return noErr;
  154. }